import cv2

def get_video_frame_count(video_path):
    try:
        # 打开视频文件
        cap = cv2.VideoCapture(video_path)
        if not cap.isOpened():
            print("无法打开视频文件")
            return 0
        # 获取视频的总帧数
        frame_count = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
        # 释放视频捕获对象
        cap.release()
        return frame_count
    except Exception as e:
        print(f"发生错误: {e}")
        return 0

